package com.cn.yang.servlet;

import com.alibaba.fastjson.JSONObject;
import com.cn.yang.model.news.NewsModel;
import com.cn.yang.service.NewsService;
import com.cn.yang.service.impl.NewsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/news/findById")
public class DateNewsFindByIdServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Integer id = req.getParameter("id")==null?0:Integer.valueOf(req.getParameter("id"));
        NewsService service = new NewsServiceImpl();
        NewsModel model = service.selectById(id);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("model",model);
        resp.getWriter().println(jsonObject);
    }
}
